local zoufa = fk.CreateSkill{
  name = "dajubei__zoufa",
}

Fk:loadTranslationTable{
  ["dajubei__zoufa"] = "奏伐",
  [":dajubei__zoufa"] = "出牌阶段限一次，你可弃置任意张花色各不同的牌并展示一名其他角色的手牌，若其手牌花色数不大于X，你对其造成1点伤害；"
  .."否则，你令一名其他角色获得弃置的牌，且本阶段内“奏伐”改为“出牌阶段限两次”（X为你以此法弃置的牌的花色数）。",

  ["#dajubei__zoufa-give"] = "奏伐：令一名其他角色获得弃置的牌",
  ["@@dajubei__zoufa-phase"] = "奏伐",

  ["$dajubei__zoufa1"] = "煌煌大势，无须诈取。",
  ["$dajubei__zoufa2"] = "开示公道，不为掩袭。",
}

local getSuit = function (id)
  return Fk:getCardById(id).suit
end

zoufa:addEffect("active", {
  anim_type = "offensive",
  max_phase_use_time = 1,
  can_use = function (self, player)
    return player:usedSkillTimes("dajubei__zoufa", Player.HistoryPhase) < (player:getMark("@@dajubei__zoufa-phase") + 1)
  end,
  min_card_num = 1,
  target_num = 1,
  card_filter = function (self, player, to_select, selected)
    return not table.contains(table.map(selected, getSuit), getSuit(to_select))
  end,
  target_filter = function (self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:throwCard(effect.cards, zoufa.name, player, player)
    if player.dead or target.dead then return end

    local hand_cards = target:getCardIds("h")
    if target:getHandcardNum() > 0 then
      room:showCards(hand_cards, target)
    end
    local suits = {}
    table.forEach(hand_cards, function (id)
      if not table.contains(suits, Fk:getCardById(id).suit) then
        table.insert(suits, Fk:getCardById(id).suit)
      end
    end)

    if #suits <= #effect.cards and target:isAlive() then
      room:damage{
        to = target,
        from = player,
        damage = 1,
        skillName = zoufa.name,
      }
    end
    if #suits > #effect.cards and player:isAlive() then
      local tos = room:askToChoosePlayers(player, {
        targets = room:getOtherPlayers(player, false),
        min_num = 1,
        max_num = 1,
        skill_name = zoufa.name,
        cancelable = false,
        prompt = "#dajubei__zoufa-give",
      })
      if #tos == 1 then
        local cards = table.filter(effect.cards, function (id)
          return room:getCardArea(id) == Card.DiscardPile
        end)
        room:obtainCard(tos[1], cards, true, fk.ReasonGive, player, zoufa.name)
      end
      room:setPlayerMark(player, "@@dajubei__zoufa-phase", 1)
    end
  end,
})

return zoufa